package com.Repository;

import com.entity.Student;
import com.entity.teacher.Teacher;
import com.entity.teacher.TeacherConnect;
import com.entity.teacher.TeacherConnect2;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface TeacherRepository extends JpaRepository<Teacher, Long>, JpaSpecificationExecutor<Teacher> {

    @Query(value = "from Teacher where tid = 1 or tid =2")
    public List<Teacher> findJpal1(); //List<Teacher>

    @Query(value = "select tid, name, age from Teacher where tid = 1 or tid =2")
    public List<Object[]> findJpal2(); //List<Object[]>


    //相当于select * , 但jqal不认*
    @Query(value = "from Teacher t, TConnect c where t.tid = c.tid")
    public List<Object> findTeacherConnect1();

    //选择需要返回的字段
    @Query(value = "select t.tid, t.age, t.name, c.id, c.connect from Teacher t, TConnect c where t.tid = c.tid")
    public List<Object> findTeacherConnect2();

    //将返回的进行包装
    @Query(value = "select new com.entity.teacher.TeacherConnect(t,c) from Teacher t, TConnect c where t.tid = c.tid")
    public List<TeacherConnect> findTeacherConnect3();

    //选择需要返回的字段
    @Query(value = "select t.tid as id, t.name as name, c.connect as connect from Teacher t, TConnect c where t.tid = c.tid")
    public List<Object[]> findTeacherConnect4();

    //1.不知道用Object好，还是Object[]
    //2.findTeacherConnect2返回的仅是值，而findTeacherConnect1是键值对,findTeacherConnect4 的as 也没用。
    //3.findTeacherConnect3和findTeacherConnect1的结果一样
    //4.没有出错，要想对返回的结果进行操作，还需要新建类吗？估计还需要学习。


}
